package com.atguigu.cloud.controller;

import cn.hutool.core.bean.BeanUtil;
import com.atguigu.cloud.entity.dto.PayDTO;
import com.atguigu.cloud.entity.po.Pay;
import com.atguigu.cloud.service.PayService;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author Jungle
 * @create 2024-04-01 8:04
 */
@Slf4j
@RestController
@RequestMapping("/pay")
public class PayController {
    @Resource
    private PayService payService;

    /**
     * 创建流水
     */
    @PostMapping("/add")
    public Boolean addPay(@RequestBody PayDTO dto) {
        log.info("==>{}", dto);
        // 忽略id
        Pay pay = BeanUtil.copyProperties(dto, Pay.class, "id");
        return payService.add(pay) > 0;

    }
    /**
     * 删除流水
     */
    @DeleteMapping("/del/{id}")
    public Boolean delPay(@PathVariable("id") Long id) {
        log.info("==>{}", id);
        // 忽略id
        return payService.delete(id)>0;
    }

    /**
     * 修改流水
     */
    @PutMapping("/update")
    public Boolean updatePay(@RequestBody PayDTO dto) {
        Pay pay = BeanUtil.copyProperties(dto, Pay.class);
        return payService.update(pay) > 0;
    }


    /**
     * 流水详情
     */
    @GetMapping("/get/{id}")
    public Pay getInfo(@PathVariable("id") Long id) {

        return payService.getById(id);
    }



    /**
     * 流水列表
     */
    @GetMapping("/list")
    public List<Pay> list() {
        return payService.getAll();
    }
}
